package cloud.simple.ui.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import cloud.simple.ui.model.User;

@Service
public class UserService {

	final String SERVICE_NAME = "cloud-simple-service";
	
	@Autowired
	RestTemplate restTemplate;
	
	@Autowired
	FeignUserService feignUserService;
	
	@SuppressWarnings("unchecked")
	// @HystrixCommand(fallbackMethod = "fallbackSearchAll")
	public List<User> searchAll() {
		// return restTemplate.getForObject("http://" + SERVICE_NAME + "/user", List.class);
		return feignUserService.searchAll();
	}

	@SuppressWarnings("unused")
	private List<User> fallbackSearchAll() {
		System.out.println("HystrixCommand fallbackMethod handle!");
		List<User> ls = new ArrayList<User>();
		User user = new User();
		user.setUsername("TestHystrix");
		ls.add(user);
		return ls;
	}

}